<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <?php include "headerNav.html" ?>
  <?php
  //获取学号
  if ($_POST['stuno']) {
    $stuno = $_POST['stuno'];
  } else {
    $stuno = '没有填写';
  }

  //获取姓名
  if ($_POST['stuname']) {
    $stuname = $_POST['stuname'];
  } else {
    $stuname = '没有填写';
  }

  //获取密码
  if ($_POST['pwd']) {
    $password = $_POST['pwd'];
  } else {
    $password = '没有填写';
  }

  //获取班级
  $classname = $_POST['classname'];

  //获取性别
  $sex = $_POST['sex'];

  //获取爱好
  if (array_key_exists('hobby', $_POST)) {
    $hobby = join(',', $_POST['hobby']);
  } else {
    $hobby = '没有任何爱好 ';
  }

  //获取手机号
  if ($_POST['mobile']) {
    $mobile = $_POST['mobile'];
  } else {
    $mobile = '没有填写';
  }

  //获取邮箱
  if ($_POST['email']) {
    $email = $_POST['email'];
  } else {
    $email = '没有填写';
  }

  switch ($_FILES['photo']['error']) {
    case 0: //成功上传
      $ftypes = ['image/gif', 'image/pjpeg', 'image/jpeg', 'image/png'];
      $type = $_FILES['photo']['type'];
      if (in_array($type, $ftypes))  //上传的文件是指定的类型
      {
        $fname = $_FILES['photo']['name'];  //上传的原始文件名
        $tmp = explode('.', $fname); //将文件名以"."分隔成两部分，分别为"php","jpg"  
        $newfname = $stuno . '.' . $tmp[1]; //新的文件名为学号              
        $destination = 'upload/' . $newfname;
        move_uploaded_file($_FILES['photo']['tmp_name'], $destination);
      } else {
        $txt = '上传文件类型不符合要求';
      }
      break;
    case 1: //文件大小超过了PHP默认的限制2MB
      $txt = '上传文件出错，文件大小超过了限制！';
      break;
    case 4: //没有选择上传文件
      $txt = '没有上传照片！';
      break;
  }
  ?>
  <main>

    <h1>注册成功，您的注册信息如下：</h1>
    学号：<?php echo $stuno ?>
    <br>
    姓名：<?php echo $stuname ?>
    <br>
    密码：<?= $password ?>
    <br>
    班级：<?= $classname ?>
    <br>
    性别：<?= $sex ?>
    <br>
    爱好：<?= $hobby ?>
    <br>
    手机：<?= $mobile ?>
    <br>
    邮箱：<?= $email ?>
    <br>
    相片：<?php
        if (isset($txt)) {
          echo $txt;    //输出错误提示
        } else {
          echo  "<img src='$destination'  style='width:150px;height:120px;'>";  //显示上传的图片
        }
        ?>
  </main>
  <?php include "Footer.html" ?>
</body>

</html>